#!/usr/bin/env bash

if [ ! -d "${PWD}/config" ]; then
  echo "Creating default configuration."
  mkdir -p "${PWD}/config";
  hass --script ensure_config -c "${PWD}/config"
  echo "
logger:
  default: info
  logs:
    custom_components.hacs: debug
    aiogithubapi: debug
    awesomeversion: debug
frontend:
  themes: !include_dir_merge_named themes

#hacs: #https://hacs.xyz/docs/configuration/legacy
#  token: CHANGE_ME
#  frontend_repo_url: http://192.168.100.50:5000
#  appdaemon: true
#  experimental: true
" >> "${PWD}/config/configuration.yaml"
fi

# Symlink the custom_components dir
rm -rf "${PWD}/config/custom_components"
ln -sf "${PWD}/custom_components" "${PWD}/config/custom_components"

echo "Installing HACS frontend"
bash "${PWD}/manage/install_frontend"

# Start Home Assistant
hass -c "${PWD}/config" --debug